const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  mode: 'development',
  entry: './src/index.ts',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js',
  },
  resolve: {
    extensions: ['.ts', '...'],
  },
  module: {
    rules: [
      {
        // js文件使用babel-loader来处理
        test: /\.?js$/,
        exclude: /(node_modules)/,
        use: {
          loader: 'babel-loader',
        }
      },
      {
        // ts文件使用ts-loader来处理
        test: /\.?ts$/,
        exclude: /(node_modules)/,
        use: {
          loader: 'ts-loader',
        }
      },
      {
        test: [/\.css$/, /\.less$/], 
        use: [
          {
            loader: 'style-loader',
            options: {
            // insert: "body",
            },
          },
          {
            loader: 'css-loader',
            options: {
              modules: false
            }
          },
          {loader: 'less-loader'}
        ],
      },
      {
        test: /\.(png|jpe?g|gif|svg)$/,
        loader: 'url-loader',
        options: {
        // limit: 10000
        }
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({ 
      template: './public/index.html' ,
      filename: 'index.html' ,
      title: 'markdownLite',
    })
  ],
  devServer: {
    static: './dist',
    host: 'localhost',
    port: 8080
  },
};